Java join() method

    join() method

    This method will allow you to provide the string joined with the provided delimiter. The delimiter will get copied for each of the string elements. If you are using the null element, then the null is added.

    Syntax-

    public static String join(CharSequence delimiter, CharSequence... elements)  

    and

    public static String join(CharSequence delimiter, Iterable<? extends CharSequence> elements)  

    Note: This method will throw NullPointerException if the specified element is null.

    Example-

    public class Simple{  
        public static void main(String[] args) {      
           String s1=join("-","How","are","you");
           System.out.println(s1);     
        }
    }